<template>
	<view style="height: 100vh; background-color: #FFFFFF;">
		<u-navbar title-color="#FFFFFF" height="48" back-icon-color="#FFFFFF" :border-bottom="false" :is-fixed="true" title="任务详情">
		</u-navbar>
		<uc-content :loading="loading">
			<view class="list-item">
				<view class="list-bottom">
					<view>任务名称:</view>
					<view>{{enterpriseTaskInfo.name}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>负责区域:</view>
					<view>{{enterpriseTaskInfo.regionName}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>任务内容:</view>
					<view>{{enterpriseTaskInfo.content}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>任务类型:</view>
					<view>{{enterpriseTaskInfo.type|type}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>开始时间:</view>
					<view>{{enterpriseTaskInfo.startTime|taskDate}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>结束时间:</view>
					<view>{{enterpriseTaskInfo.endTime|taskDate}}</view>
				</view>
			</view>
			
			<!-- 两个按钮状态和类型不是0时，是我已知晓 ，为0时就是巡检 -->
			<u-button :disabled=disabled v-if="enterpriseTaskInfo.type!=0&&enterpriseTaskInfo.status!=0"
				@click="AlreadyKnow(enterpriseTaskInfo.ucId)" type="primary" shape="square" style="margin-top: 10px;">我已知晓</u-button>
			<u-button @click="taskReturn(enterpriseTaskInfo.ucId)" type="error" style=" margin-top: 10px"
				v-if="enterpriseTaskInfo.status==1">退回任务</u-button>
			<u-button @click="taskChange(enterpriseTaskInfo.ucId)" type="primary" style=" margin-top: 10px"
				v-if="enterpriseTaskInfo.status==1">交班</u-button>
		</uc-content>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				enterpriseTaskInfo: {},
				taskId: "",
				loading: false,
				show: false,
				disabled: false,
				logId:"",
			}
		},
		onLoad(e) {
			this.taskId = e.ucId
		},
		onShow() {
			this.initView(this.taskId)
		},
		methods: {
			initView(val) {
				this.loading = true
				this.enterpriseTaskInfo = {}
				this.pageNum = 0
				this.getInEnterpriseTaskVo(val)
			},
			getInEnterpriseTaskVo(val) {
				this.utils.request("/api/app/enterpriseTask/getInEnterpriseTaskVo", {
					ucId: val
				}, "post", "app", true).then(res => {
					this.loading = false
					this.enterpriseTaskInfo = res.data
					if (res.data.readtime == null) {
						console.log(res.data)
						this.updateReadTime(res.data.ucId)
					}
				}).catch(error => {
					this.loading = false
					console.log(error)
				})
			},
			// 我已知晓按钮，点击后修改状态
			AlreadyKnow(val) {
				this.utils.request("/api/app/task/updateInDailyTasksType", {
					ucId: val
				}, "post", "app", true).then(res => {
					this.initView(val)
					this.disabled = true;
				}).catch(error => {
					console.log(error)
				})
			},
			Inspection() {
				//获取地址信息上传内容
				window.native.getLocation(res => {
					this.utils.request("/api/admin/user/reportUserLocation", {
						location: res.data.addr,
						longitude: res.data.longitude,
						latitude: res.data.latitude
					}, "post", "app", true).then(res => {
						console.log(res)
					}).catch(error => {
						console.log(error)
					})
				})
				this.addInspectionTaskLog(this.enterpriseTaskInfo.ucId)
				let userInfo = this.$store.getters.userInfo

			},
			fireAlarm() {
				let userInfo = this.$store.getters.userInfo
				window.native.fireAlarm({
					channelId: userInfo.ucId,
					disPlayName: userInfo.userName
				})
			},
			taskReturn(val) {
				this.utils.request("/api/app/task/taskReturn", {
					ucId: val
				}, "post", "app", true).then(res => {
					uni.navigateBack()
				}).catch(error => {
					console.log(error)
				})
			},
			taskChange(val) {
				this.utils.request("/api/app/task/taskChange", {
					ucId: val
				}, "post", "app", true).then(res => {
					uni.navigateBack()
				}).catch(error => {
					console.log(error)
				})
			},
			addInspectionTaskLog(val){
				this.utils.request("/api/app/enterpriseTask/addInsepectionTaskLog", {
					taskId: val
				}, "post", "app", true).then(res => {
					console.log(res.data)
					this.logId=res.data
					window.native.rounds({
					    ucId:this.logId,
						title:val
					})
				}).catch(error => {
					console.log(error)
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	@import "../../../uview-ui/libs/css/style.components.scss";

	.list-item {
		padding: 20rpx 40rpx;
		background-color: #fff;
		border-bottom: #999999 1px dashed;

		.list-bottom {
			display: flex;
			margin-top: 10rpx;
			font-size: 28rpx;
			justify-content: space-between;
			color: #333;
		}

		.list-center {
			margin-top: 20rpx;
			font-size: 28rpx;
			color: #999999;
		}
	}
</style>
